﻿using Abp.AutoMapper;
using Abp.Runtime.Validation;
using NetCore.Dtos;
using NetCore.Entities.Projects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Projects.Dtos
{
    /// <summary>
    /// 项目
    /// </summary>
    [AutoMap(typeof(Project)), Description("项目")]
    public class ProjectDto : BaseDto
    {
        public ProjectDto()
        {
            Attachments = new List<ProjectAttachmentDto>();
            Users = new List<ProjectUserDto>();
        }
        /// <summary>
        /// 项目附件
        /// </summary>
        [Description("项目附件")]
        public List<ProjectAttachmentDto> Attachments { get; set; }
        /// <summary>
        /// 项目用户
        /// </summary>
        [Description("项目用户")]
        public List<ProjectUserDto> Users { get; set; }
        /// <summary>
        /// 课程期数
        /// </summary>
        [Description("期数")]
        public int Period { get; set; }
        /// <summary>
        /// 开始日期
        /// </summary>
        [Description("开始日期")]
        public DateTime StartDate { get; set; }
        /// <summary>
        /// 计划结束日期
        /// </summary>
        [Description("计划结束日期")]
        public DateTime? PlanEndDate { get; set; }
        /// <summary>
        /// 结束日期
        /// </summary>
        [Description("结束日期")]
        public DateTime? EndDate { get; set; }
        /// <summary>
        /// 总金额
        /// </summary>
        [Description("总金额")]
        public decimal? Amount { get; set; }
        /// <summary>
        /// 百分比
        /// </summary>
        [Description("百分比")]
        public decimal? Percent { get; set; }
        /// <summary>
        /// 单价
        /// </summary>
        [Description("单价")]
        public decimal? Price { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        [Description("备注")]
        public string Remark { get; set; }
        /// <summary>
        /// 项目示意图文件服务器绝对路径
        /// </summary>
        [Description("项目示意图")]
        public string MapPath { get; set; }
        /// <summary>
        /// 创建页面没有保存数据前，使用保存文件功能保存的缓存文件，生成一个全球唯一Guid字符串作为目录，
        /// ~/upload/temp/{UploadGuid}/目录下，以区别网站的并发情况
        /// </summary>
        [Description("上传Guid")]
        public string UploadGuid { get; set; }


        public override void AddValidationErrors(CustomValidationContext context)
        {
            //if (!Phone.Validate())
            //{
            //    context.Results.Add(new ValidationResult("请输入正确的电话号码!"));
            //}
            //if (Files.Count > 20)
            //{
            //    context.Results.Add(new ValidationResult("批量上传文件最多20个"));
            //}
            if (StartDate > EndDate)
            {
                context.Results.Add(new ValidationResult("时间范围不正确!"));
            }
            EndDate = EndDate?.Date.AddDays(1).AddSeconds(-1);
        }
    }
}
